var tmArr = new Array(60);
//内部定时器
var t1;
//当前显示的元素序号
var index = 0;
$(document).ready(function () {
    //加载页面时调用
    getInfo();
    //设置每2分钟循环一次
    window.setInterval(refreshInfo, 120000);
    function refreshInfo() {
        //关闭内部计定时器
        window.clearInterval(t1);
        $('#small').empty();
        console.log("=============接口读取时间============"+CurentTime()); //1495302061441
        getInfo();
    }
});

//根据接口获取数据并且循环输出
function getInfo() {
    $.ajax({
        url : "http://10.0.1.100/climb/erpOrder/getDisplay?loadUnloadPlatform=6",
        type : "GET",
        dataType : "jsonp", // 返回的数据类型，设置为JSONP方式
        jsonpCallback: 'success', //设置回调函数名
        success: function(res) {
            tmArr = res;
            console.log(tmArr);
            if (tmArr.length > 0){
                var str = "<div class='firststep'>"+tmArr[0].vehicleInfo+"</div><div class='step'><marquee width='124px;'>"+tmArr[0].customerName+"</marquee></div>";
                $('#small').append(str);
                t1 = window.setInterval(pushInfo, 10000);
                function pushInfo() {
                    $('#small').empty();
                    console.log("=============当前显示时间============"+CurentTime()+"  当前index为"+index);
                    if (index >= tmArr.length){
                        index = 0;
                    }
                    var str = "<div class='firststep'>"+tmArr[index].vehicleInfo+"</div><div class='step'><marquee width='124px;'>"+tmArr[index].customerName+"</marquee></div>";
                    $('#small').append(str);
                    index++;
                }
            }
        }
    });
}
function CurentTime() {
    var now = new Date();

    var year = now.getFullYear();       //年
    var month = now.getMonth() + 1;     //月
    var day = now.getDate();            //日

    var hh = now.getHours();            //时
    var mm = now.getMinutes();          //分
    var ss = now.getSeconds();           //秒

    var clock = year + "-";

    if(month < 10)
        clock += "0";

    clock += month + "-";

    if(day < 10)
        clock += "0";

    clock += day + " ";

    if(hh < 10)
        clock += "0";

    clock += hh + ":";
    if (mm < 10) clock += '0';
    clock += mm + ":";

    if (ss < 10) clock += '0';
    clock += ss;
    return(clock);
}